package com.qiwenshare.file.dto.archive;


import com.qiwenshare.file.domain.ArchiveFile;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 档案信息表(Archive)表实体类
 *
 * @author makejava
 * @since 2023-10-08 21:09:13
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ArchiveCodeDTO {

    private String departmentCode;
    private String archiveType;
    private String archiveLevel;
    private String num;
    private String year;

    public String getCode() {
        if (StringUtils.isBlank(num)) {
            num = "0";
        }else {
            String[] numArr = StringUtils.split(num, "_");
            if (numArr.length == 5) {
                if (numArr[3].matches("\\d+")) {
                    num = String.valueOf(Integer.parseInt(numArr[3]) + 1);
                }else {
                    num = "0";
                }
            }else {
                num = "0";
            }
        }

        if (Integer.parseInt(num) < 10) {
            num = "00000" + num;
        }else if ( Integer.parseInt(num) < 100 && Integer.parseInt(num) >= 10){
            num = "0000" + num;
        }else if ( Integer.parseInt(num) < 1000 && Integer.parseInt(num) >= 100){
            num = "000" + num;
        }else if ( Integer.parseInt(num) < 10000 && Integer.parseInt(num) >= 1000){
            num = "00" + num;
        }else if ( Integer.parseInt(num) < 100000 && Integer.parseInt(num) >= 10000){
            num = "0" + num;
        }
        return departmentCode + "_" + archiveType + "_00" + archiveLevel + "_" + num + "_" + year;
    }
}

